using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace ProjectSurvival
{
    public class Dissolve : MonoBehaviour
    {
        public Material Material;
        private static readonly int Color = Shader.PropertyToID("_Color");
        private static readonly int Fade = Shader.PropertyToID("_Fade");
        public Color DissolveColor;
        void Start()
        {
            var material = Instantiate(Material);
            var sprite = this.GetComponent<SpriteRenderer>();
            sprite.material = material;
            material.SetColor(Color,DissolveColor);
            ActionKit.Lerp(1f, 0f, 0.5f, (value) =>
            {
                material.SetFloat(Fade, value);
                this.LocalScale(1 + (1 - value));
            }).Start(this, () =>
            {
                Destroy(material);
                this.DestroyGameObjGracefully();
            });
        }

        // Update is called once per frame
        void Update()
        {
        }
    }
}